
globalExeCmd = nil

function ttbuild:getEnv(tag)
	return ttbuild.script[tag]
end

function ttbuild:bc_c(src,obj,cflag,log)
	local cmd = ttbuild:getEnv("bc_c")
	if nil == cmd or nil == src or nil == obj then
		return -1
	end
	local templateCmd = table.concat(cmd," ")
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_HOME}",ttbuild.home)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_SOURCE}",src)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_OBJECT}",obj)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_CFLAGS}",cflag)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_LOG}",log)
	if ttbuild.showcmd then
		print(templateCmd)
	end
	globalExeCmd = templateCmd
	local ret = os.execute(templateCmd)
	return ret
end

function ttbuild:bc_cxx(src,obj,cflag,log)
	local cmd = ttbuild:getEnv("bc_cxx")
	if nil == cmd or nil == src or nil == obj then
		return -1
	end
	local templateCmd = table.concat(cmd," ")
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_HOME}",ttbuild.home)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_SOURCE}",src)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_OBJECT}",obj)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_CFLAGS}",cflag)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_LOG}",log)
	if ttbuild.showcmd then
		print(templateCmd)
	end
	globalExeCmd = templateCmd
	local ret = os.execute(templateCmd)
	return ret
end

function ttbuild:bc_link(src,obj,flag,log)
	local cmd = ttbuild:getEnv("bc_link")
	if nil == cmd or nil == src or nil == obj then
		return -1
	end
--	os.remove(obj)
	local templateCmd = table.concat(cmd," ")
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_HOME}",ttbuild.home)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_SOURCE}",src)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_OBJECT}",obj)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_LOG}",log)
	if ttbuild.showcmd then
		print(templateCmd)
	end
	globalExeCmd = templateCmd
	local ret = os.execute(templateCmd)
	return ret
end

function ttbuild:llc(src,obj,flag,log)
	local cmd = ttbuild:getEnv("llc")
	if nil == cmd or nil == src or nil == obj then
		return -1
	end
	local templateCmd = table.concat(cmd," ")
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_HOME}",ttbuild.home)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_SOURCE}",src)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_OBJECT}",obj)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_LOG}",log)
	if ttbuild.showcmd then
		print(templateCmd)
	end
	globalExeCmd = templateCmd
	local ret = os.execute(templateCmd)
	return ret
end

function ttbuild:as(src,obj,flag,log)
	local cmd = ttbuild:getEnv("as")
	if nil == cmd or nil == src or nil == obj then
		return -1
	end
	local templateCmd = table.concat(cmd," ")
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_HOME}",ttbuild.home)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_SOURCE}",src)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_OBJECT}",obj)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_LOG}",log)
	if ttbuild.showcmd then
		print(templateCmd)
	end
	globalExeCmd = templateCmd
	local ret = os.execute(templateCmd)
	return ret
end

function ttbuild:ar(src,obj,flag,log)
	local cmd = ttbuild:getEnv("ar")
	if nil == cmd or nil == src or nil == obj then
		return -1
	end
	local templateCmd = table.concat(cmd," ")
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_HOME}",ttbuild.home)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_SOURCE}",src)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_OBJECT}",obj)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_LOG}",log)
	if ttbuild.showcmd then
		print(templateCmd)
	end
	globalExeCmd = templateCmd
	local ret = os.execute(templateCmd)
	return ret
end

function ttbuild:ld_c(src,obj,ldflag,log)
	local cmd = ttbuild:getEnv("ld_c")
	if nil == cmd or nil == src or nil == obj then
		return -1
	end
	local templateCmd = table.concat(cmd," ")
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_HOME}",ttbuild.home)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_SOURCE}",src)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_OBJECT}",obj)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_LDFLAGS}",ldflag)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_LOG}",log)
	if ttbuild.showcmd then
		print(templateCmd)
	end
	globalExeCmd = templateCmd
	local ret = os.execute(templateCmd)
	return ret
end

function ttbuild:ld_cxx(src,obj,ldflag,log)
	local cmd = ttbuild:getEnv("ld_cxx")
	if nil == cmd or nil == src or nil == obj then
		return -1
	end
	local templateCmd = table.concat(cmd," ")
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_HOME}",ttbuild.home)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_SOURCE}",src)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_OBJECT}",obj)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_LDFLAGS}",ldflag)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_LOG}",log)
	if ttbuild.showcmd then
		print(templateCmd)
	end
	globalExeCmd = templateCmd
	local ret = os.execute(templateCmd)
	return ret
end

function ttbuild:ld_so(src,obj,ldflag,log)
	local cmd = ttbuild:getEnv("ld_so")
	if nil == cmd or nil == src or nil == obj then
		return -1
	end
	local templateCmd = table.concat(cmd," ")
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_HOME}",ttbuild.home)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_SOURCE}",src)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_OBJECT}",obj)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_LDFLAGS}",ldflag)
	templateCmd = string.gsub(templateCmd,"${TT_TEMPLATE_LOG}",log)
	if ttbuild.showcmd then
		print(templateCmd)
	end
	globalExeCmd = templateCmd
	local ret = os.execute(templateCmd)
	return ret
end
